
var mysqlPool = require('../lib/db.js');
var md5 = require('../lib/md5.js');

exports.login = function(username,password,callBack) {
	var pwd_md5 = md5(password);
	console.log(pwd_md5);
	var selectSql = 'select id,loginname,username,avatar from tb_user where loginname = ? and password = ?';
	
	mysqlPool.query(selectSql,[username,pwd_md5],function(err, rows, fields) {
		if (err) callBack(err);
		callBack(null,rows);
	});
};

exports.register = function(username,password,callBack) {
	var selectSql = 'select count(*) as count from tb_user where loginname = ?';
	
	mysqlPool.query(selectSql,[username],function(err, rows, fields) {
		if (err) callBack(err);
		if(rows[0].count == 0) {
			
		}
		callBack(null,rows);
	});
};